package com.combetter.changxing;

import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * Created by Mark.fan on 2018/5/4.
 */

public class AppExecutors {
    private final Executor mDiskIO;

    private final Executor mNetworkIO;

    private final Executor mMainThreadIO;

    public AppExecutors() {
        this(Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(3), new MainThreadExcutor());
    }

    public AppExecutors(Executor diskIO, Executor networkIO, Executor mainThreadIO) {
        mDiskIO = diskIO;
        mNetworkIO = networkIO;
        mMainThreadIO = mainThreadIO;
    }

    public Executor diskIO() {
        return mDiskIO;
    }

    public Executor networkIO() {
        return mNetworkIO;
    }

    public Executor mainIO() {
        return mMainThreadIO;
    }
    public static class MainThreadExcutor implements Executor {

        private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
        @Override
        public void execute(@NonNull Runnable runnable) {
            mainThreadHandler.post(runnable);
        }
    }

}
